//
//  YSProdReviewItemView.m
//  Yueshi
//
//  Created by Northwan on 15/10/11.
//  Copyright © 2015年 悦食中国. All rights reserved.
//

#import "YSProdReviewItemView.h"
#import "YSLevelView.h"
#import "YSPhotosView.h"
#import "YSSellerReplyView.h"

@interface YSProdReviewItemView()
@property (strong, nonatomic) UIImageView *avatarView;
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UILabel *leveLabel;
@property (strong, nonatomic) YSLevelView *scoreView;
@property (strong, nonatomic) UILabel *timeLabel;
@property (strong, nonatomic) UILabel *contentLabel;
@property (strong, nonatomic) YSPhotosView *photosView;
@property (strong, nonatomic) YSSellerReplyView *sellerReplyView;
@property (strong, nonatomic) UIView *spliteView;
@end

@implementation YSProdReviewItemView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        UIImageView *avatarView = [[UIImageView alloc]init];
        avatarView.clipsToBounds = YES;
        avatarView.layer.masksToBounds = YES;
        avatarView.layer.cornerRadius = 72/4;
        [avatarView setSize:CGSizeMake(72/2, 72/2)];
        [self addSubview:avatarView];
        _avatarView = avatarView;
        
        UILabel *nameLabel = [[UILabel alloc]init];
        [nameLabel setFont:SYS_FONT(nameFont)];
        [nameLabel setTextColor:publicTextColor];
        [self addSubview:nameLabel];
        _nameLabel = nameLabel;
        
        UILabel *levelLabel = [[UILabel alloc]init];
        [levelLabel setFont:SYS_FONT(levelFont)];
        [levelLabel setTextColor:HEXColor(@"#9e9e9e")];
        [levelLabel setText:@"好评度"];
        [self addSubview:levelLabel];
        _leveLabel = levelLabel;
        
        YSLevelView *scoreView = [[YSLevelView alloc]initWithSourceType:ReviewSourceType];
        scoreView.userInteractionEnabled = NO;
        [self addSubview:scoreView];
        _scoreView = scoreView;
        
        UILabel *timeLabel = [[UILabel alloc]init];
        [timeLabel setTextColor:HEXColor(@"#9e9e9e")];
        [timeLabel setFont:SYS_FONT(timeFont)];
        [self addSubview:timeLabel];
        _timeLabel = timeLabel;
        
        UILabel *contentLabel = [[UILabel alloc]init];
        [contentLabel setFont:SYS_FONT(timeFont)];
        [contentLabel setTextColor:HEXColor(@"#9e9e9e")];
        contentLabel.numberOfLines = 0;
        [self addSubview:contentLabel];
        _contentLabel = contentLabel;
        
        YSPhotosView *photoView = [[YSPhotosView alloc]init];
        photoView.isShowProgress = NO;
        [self addSubview: photoView];
        _photosView = photoView;
        
        YSSellerReplyView *sellerReplyView = [[YSSellerReplyView alloc] init];
        [self addSubview:sellerReplyView];
        _sellerReplyView = sellerReplyView;
        
        UIView *spliteView = [[UIView alloc]init];
        [spliteView setBackgroundColor:PUBLIC_BG];
        [self addSubview:spliteView];
        _spliteView = spliteView;
    }
    return self;
}

-(void)setReviewItemFrame:(YSProdReviewItemFrame *)reviewItemFrame{
    _reviewItemFrame = reviewItemFrame;
    YSProdComment *comment = reviewItemFrame.comment;
    
    _avatarView.x = reviewItemFrame.avatarFrame.origin.x;
    _avatarView.y = reviewItemFrame.avatarFrame.origin.y;
    [_avatarView setImageURLStr:comment.userImg];
    
    [_nameLabel setText:comment.userName];
    _nameLabel.frame = reviewItemFrame.nameFrame;
    
    _leveLabel.frame = reviewItemFrame.leveltTipFrame;
    
    _scoreView.x = reviewItemFrame.levelFrameX;
    _scoreView.y = reviewItemFrame.levelFrameY;
    [_scoreView setLevel:comment.score];
    
    _timeLabel.frame = reviewItemFrame.timeFrame;
    [_timeLabel setText:comment.createTime];
    
    _contentLabel.frame = reviewItemFrame.contentFrame;
    [_contentLabel setText:comment.comment];
    
    if(comment.commentImage.count){
        [_photosView setHidden:NO];
        _photosView.x = reviewItemFrame.photosFrameX;
        _photosView.y = reviewItemFrame.photosFrameY;
        [_photosView addPhotos:comment.commentImage];
    }else{
        [_photosView setHidden:YES];
    }
    
    if (comment.reComment) {
        _sellerReplyView.hidden = NO;
        _sellerReplyView.frame = reviewItemFrame.sellerReplyFrame;
        [_sellerReplyView setReplyContent:comment.reComment];
    }else{
        _sellerReplyView.hidden = YES;
    }
    
    _spliteView.frame = reviewItemFrame.spliteFrame;
    
    [self setFrame:reviewItemFrame.frame];
}



@end
